@extends('admin::layouts.master')
@section('style')
<meta name="_token" content="{{ csrf_token() }}"/>
<style>
    .ipaywrap{
        position: relative;
    }
    .tooltip.top{
        top:-31px;
    }
</style>
@stop
@section('content-header')
	
	<h1>
		所有单子({!! $shipments->count() !!})
		&middot;
		<small>{!! link_to_route('admin.shipment.create', '添加') !!}</small>
	</h1>
@stop
@section('content')

   <table class="table">
		<thead>
                <th class="text-center">出货单号</th>
			<th class="text-center">客户/单位</th>
                        <th class="text-center">已付金额&nbsp;&nbsp;&nbsp;&nbsp;<i class="fa fa-edit"></i></th>
			<th class="text-center">总金额</th>
			<th class="text-center">总数量</th>
                        <th class="text-center">交货日期</th>
			<th class="text-center">操作</th>
		</thead>
                <tbody>
                    @foreach ($shipments as $s)
                    <tr @if($s->status==0)class="warning" @endif>
                        <td class="text-center" @if($s->status==0)style="color:#777;" @endif>{!! $s->codeno !!}</td>
                        <td class="text-center" @if($s->status==0)style="color:#777;" @endif>{!! $s->client_company !!}</td>
                        <td class="text-center" data-shipid="{!! $s->id !!}" @if($s->status==0)style="color:#777;" @else style="cursor:pointer;" onclick="update_pay(this)" @endif><span class="paywrap"><span class="pay">{!! $s->pay !!}</span>元</span><div class="ipaywrap" style="display: none;"><input type="text" style="width: 70px;margin: auto;" value="{!! $s->pay !!}" data-shipid="{!! $s->id !!}" placeholder="已付￥"  class="ipay form-control text-center" />
                            <div class="tooltip top" role="tooltip">
      <div class="tooltip-arrow"></div>
      <div class="tooltip-inner">
        Tooltip on the top
      </div>
    </div>
                            </div></td>
                        <td class="text-center" @if($s->status==0)style="color:#777;" @endif>{!! $s->all_price+$s->all_install_price !!}元</td>
                        <td class="text-center" @if($s->status==0)style="color:#777;" @endif>{!! $s->ship_nums !!}</td>
                        <td class="text-center">{!! $s->jiaohuo_at !!}</td>
                        <td class="text-center">
                            @include('admin.common.chakan', ['data' => $s])
                            <a href="{!! route('admin.shipment.edit', $s->id) !!}">编辑</a>
                            &middot;
                            @include('admin.common.chexiao', ['data' => $s, 'name' => 'shipment','what'=>'单子'])
                        </td>
                    </tr>
                    @endforeach
                </tbody>
</table>

<div class="text-center">
	{!! $shipments->render() !!}
</div>

@stop
@section('script')
<script>
function update_pay(obj){
    this_obj=$(obj);
    var paywrap=this_obj.find(".paywrap");
    var payobj=paywrap.find(".pay");
    paywrap.hide();
    var input=this_obj.find(".ipaywrap");
    input.show();
    var ipay=input.find(".ipay");
    ipay.focus();
    ipay.blur(function(){
        var shipid=ipay.data("shipid");
        var val=ipay.val();
        if(isNaN(val)){
           alert("金额有误");
           ipay.focus();
           return false;
        }
        $.ajax({
                        type: 'POST',
                        url: '{!! route('ajaxupdatepay') !!}',
                        data:{"id":shipid,'pay':val},
                        dataType: 'json',
                        headers: {
                        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                        },
                        success: function(data){
                           if(data.status==1){
                               payobj.html(val);
                               input.hide();
                               paywrap.show();
                           }else{
                               if(data.status==-2){
                                   tooltip(ipay,"已付金额超出");
                               }else{
                                   tooltip(ipay,"修改失败");
                               }
                               ipay.focus();
                           }
                        },
                        error: function(xhr, type){

                        }
                    });
        
    });
    
}
function tooltip(inputobj,msg){
    var tooltipobj= inputobj.parent().find("div[role='tooltip']");
    tooltipobj.find(".tooltip-inner").html(msg);
    var w=parseInt(tooltipobj.width()/2);
    tooltipobj.css({"opacity":1,"left":"50%","margin-left":-w+"px"});
    window.setTimeout(function(){
        tooltipobj.css("opacity",0);
    },3000);
}
</script>
@endsection